//package com.linfeng.gateway.filter;
//
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.jwt.JWTUtil;
//import com.linfeng.common.exception.CustomException;
//import com.linfeng.common.exception.CustomExceptionCode;
//import com.linfeng.common.tools.TokenTools;
//import com.linfeng.gateway.properties.JwtProperties;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.annotation.Order;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.regex.Pattern;
//
//@Slf4j
//@Component
//@Order(-100)
//public class AuthorizeFilter implements GlobalFilter {
//
//    private static final String TOKEN_PREFIX = "Authorize_";
//
//    private static final String TOKEN_KEY = "token";
//
//    @Autowired
//    private JwtProperties jwtProperties;
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//
//        ServerHttpRequest request = exchange.getRequest();
//        ServerHttpResponse response = exchange.getResponse();
//
//        List<String> filterUrl = jwtProperties.getFilterUrl();
//
//        String path = request.getURI().getPath();
//        if (filterUrl.stream().filter(url -> Pattern.matches(url, path)).findFirst().isPresent()) {
//            return chain.filter(exchange);
//        }
//
//        String token = request.getHeaders().getFirst(TOKEN_KEY);
//        // token校验
//        if (StrUtil.isEmpty(token)) {
//            throw new CustomException(CustomExceptionCode.LOGIN_FAIL);
//        } else {
//            // token 验证
//            TokenTools.verify(token);
//        }
//
//        return chain.filter(exchange);
//    }
//
//    public static void main(String[] args) {
//        Map map = new HashMap();
//        map.put("userId", 100000);
//        map.put("date", new Date());
//        log.info("map---{}", map);
//        String token = JWTUtil.createToken(map, "linfeng".getBytes());
//        System.out.println(token);
//    }
//}
